package com.three.server.unit;

import com.three.common.request.FenceRequest;
import com.three.server.init.Fence;
import org.springframework.stereotype.Component;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

/**
 * @ProjectName : drive
 * @PackageName : com.three.server.unit
 * @ClassName : FenceUtil
 * @Author : ZhouTeng
 * @CreateTime : 2023/10/24 16:18
 */

@Component
public class FenceUtil {
    public static final int ZERO =0;


    public static String query(FenceRequest fenceRequest){
        List<Map<Map<String, String>, String>> fence = Fence.fence();
        fence.forEach(System.out::println);
        String fecnceName = fence.stream().map(item -> {
                return item.get(item.keySet().stream().filter(key ->
                        fenceRequest.getLatitude().compareTo(new BigDecimal(key.get("ONE").split(",")[0])) > ZERO &&
                        fenceRequest.getLongitude().compareTo(new BigDecimal(key.get("ONE").split(",")[1])) < ZERO &&
                        fenceRequest.getLatitude().compareTo(new BigDecimal(key.get("TWO").split(",")[0])) < ZERO &&
                        fenceRequest.getLongitude().compareTo(new BigDecimal(key.get("TWO").split(",")[1])) < ZERO &&
                        fenceRequest.getLatitude().compareTo(new BigDecimal(key.get("THREE").split(",")[0])) < ZERO &&
                        fenceRequest.getLongitude().compareTo(new BigDecimal(key.get("THREE").split(",")[1])) > ZERO &&
                        fenceRequest.getLatitude().compareTo(new BigDecimal(key.get("FOUR").split(",")[0])) > ZERO &&
                        fenceRequest.getLongitude().compareTo(new BigDecimal(key.get("FOUR").split(",")[1])) > ZERO
                ).findFirst().get());
            }
        ).findFirst().orElse(null);
        return fecnceName;
    }
}
